package com.xdcplus.web.common.enums;

import cn.hutool.core.lang.Assert;

public enum BdOpeEnum {
    FPCB_OPE("FPCB", "分片拆包", 0),
    TEX_OPE("TEX", "制绒", 1),
    DIF_OPE("DIF", "扩散", 2),
    BSG_OPE("BSG", "前清洗", 3),
    KS_OPE("KS", "刻蚀", 4),
    ALD_OPE("ALD", "PEALD-多晶硅", 5),
    ANN_OPE("ANN", "退火", 6),
    PSG_OPE("PSG", "清洗", 7),
    RD_OPE("RD", "后清洗（去绕镀）", 8),
    NALD_OPE("NALD", "ALD氧化铝", 9),
    ALDZ_OPE("ALD_Z", "PE正膜", 10),
    PECVD_OPE("PECVD", "PE背膜", 11),
    PRT_OPE("PRT", "丝网印刷", 12),
    IVT_OPE("IVT", "分检测试", 13);

    private String code;
    private String desc;
    private Integer serial;

    BdOpeEnum(String code, String desc, Integer serial) {
        this.code = code;
        this.desc = desc;
        this.serial = serial;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getSerial() {
        return serial;
    }

    public static boolean isInclude(String code) {
        boolean include = false;
        for (BdOpeEnum e : BdOpeEnum.values()) {
            if (e.getCode().equals(code)) {
                include = true;
                break;
            }
        }
        return include;
    }

    public static BdOpeEnum getByCode(String code) {
        BdOpeEnum BdOpeEnum = null;
        for (BdOpeEnum e : BdOpeEnum.values()) {
            if (e.getCode().equals(code)) {
                BdOpeEnum = e;
                break;
            }
        }
        Assert.notNull(BdOpeEnum, "站点不存在");

        return BdOpeEnum;
    }

    public static BdOpeEnum before(BdOpeEnum before) {
        if (isInclude(before.getCode())) {
            if (before.getSerial() > 1) {
                for (BdOpeEnum e : BdOpeEnum.values()) {
                    if (e.getSerial().equals(before.getSerial() - 1)) {
                        return e;
                    }
                }
            }
        }
        return null;
    }

    public static BdOpeEnum next(BdOpeEnum next) {
        if (isInclude(next.getCode())) {
            if (next.getSerial() >= 1) {
                for (BdOpeEnum e : BdOpeEnum.values()) {
                    if (e.getSerial().equals(next.getSerial() + 1)) {
                        return e;
                    }
                }
            }
        }
        return null;
    }

    /**
     * 根据当前工序获取下一个工序
     * @param opeCode
     * @return
     */
    public  static String getNextOpeCode(String opeCode){
        BdOpeEnum now = BdOpeEnum.getByCode(opeCode);
        BdOpeEnum next = BdOpeEnum.next(now);
        return next.getCode();
    }

}
